//
// Created by miaomiaole on 2024/6/22.
//


#include <iostream>
#include "Base.h"
#include <memory>

using namespace std;

void base_test() {
    // 栈中分配（自动销毁对象）
    SpreadSheetCell first;
    SpreadSheetCell second{2, "hello"};
    SpreadSheetCell mycell{3}, anothercell(4);


    // 使用移动构造函数（语法糖，右移动，等价于new SpreadSheetCell(199))
    SpreadSheetCell *moveGenerate{new SpreadSheetCell(199)};

    SpreadSheetCell *copy1{nullptr};
    // error
    // copy1->display();

    // 使用new 对象分配（堆存储）
    SpreadSheetCell *obj = new SpreadSheetCell(10);


    // 使用智能指针代替 new分配
    auto smartCellp{make_unique<SpreadSheetCell>(19)};

    delete obj;

    std::cout << "=========================================" << std::endl;

    //拷贝构造函数
    SpreadSheetCell myCell2{&second};

    std::cout << "addr1:" << &myCell2 << " arr2:" << &second << std::endl;

    SpreadSheetCell myCell3{SpreadSheetCell(10, "345")};

    std::cout << "=========================================" << std::endl;


    auto sheet = new SpreadSheetCell{12, "hello"};
    auto sheet2 = SpreadSheetCell{sheet};

    sheet->setInitValue(1000);
    sheet->setVariableName("hello 123456");


    std::cout << sheet2.getVariableName() << std::endl;
}

void base_extend() {

    Derived derived;
    derived.go();

    // 调用父类析构函数
    // 多态，ref 与 derived 相同
    Base &ref{derived};

    // 拷贝构造函数，创建新对象
    Base ref_1{derived};

    std::cout << "addr derived :" << &derived << " addr device " << &ref_1 << " base addr :" << &ref << std::endl;
    ref.go();

    ref_1.go();
    std::cout << "======================" << std::endl;

    // 重写（重写父类需要加上virtual）
    //子类代替父类 子类需要重写父类析构函数
    // 多态，===>Derived
    Base *ptr = new Derived();
    delete ptr;

}

void base_test_3() {
    derived derived;
    auto my_class_prt = new my_class();

    my_class_prt->performTask();

    delete my_class_prt;
}

void use_template(){
    Container<int, Array> container;
    container.fill(5);
    container.print();
}
int main() {
    // 使用变量代替 lambda


}